﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using System.Data;
using University.Workshop.DataAccess;

[assembly: CLSCompliant(true)]
namespace University.Workshop.Business
{
    public static class UserManager
    {
        public static bool InsertNewUser(Manager newUser, string typeManager) 
        {
            return UserDataAccess.InsertNewUser(newUser, typeManager);
        }
        public static bool ModifyUser(Manager user, string idUser)
        {
            return UserDataAccess.ModifyUser(user, idUser);
        }
        public static bool DisableUser(string idUser)
        {
            return UserDataAccess.DisableUser(idUser);
        }
        public static bool UserExists(string userName)
        {
            return UserDataAccess.UserExists(userName);
        }
        public static bool ModifyPasswordUser(string userName, string password, string newPassword)
        {
            return UserDataAccess.ModifyPasswordUser(userName, password, newPassword);
        }
        public static DataTable LoadDataGridViewUser() 
        {            
            return UserDataAccess.LoadDataGridViewUser();
        }
        public static DataTable LoadDataGridViewSearchUser(string searchUser)
        {            
            return UserDataAccess.LoadDataGridViewSearchUser(searchUser);
        }
        public static string[] LogOnUser(string userName, string password)
        {
            string[] userData = new string[4];
            if (ValidateFields.SearchFieldValidation(userName) && ValidateFields.SearchFieldValidation(password))
            {
                DataSet dataSet = UserDataAccess.ExtractLogOnUser(userName, password);
                if (dataSet != null)
                {
                    userData[0] = dataSet.Tables[0].Rows[0]["FirstName"].ToString();
                    userData[1] = dataSet.Tables[0].Rows[0]["LastName"].ToString();
                    userData[2] = dataSet.Tables[0].Rows[0]["UserName"].ToString();
                    userData[3] = dataSet.Tables[0].Rows[0]["CiManager"].ToString();
                    return userData;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
        public static bool ValidateConfirmPassword(string password, string confirmPassword) 
        {
            if (password == confirmPassword)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static string LoadDataManager(string searchUser)
        {
            DataSet dataSet = UserDataAccess.LoadDataUser(searchUser);
            string user;
            if (dataSet != null)
            {
                user = dataSet.Tables[0].Rows[0]["LastName"].ToString();
                user += "," + dataSet.Tables[0].Rows[0]["FirstName"].ToString();
                return user;
            }
            else
            {
                return "Manager not Exist";
            }   
        }
    }
}
